package com.summatech.gwt.mvp.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.inject.Inject;
import com.mvp4g.client.event.EventFilter;
import com.summatech.gwt.mvp.client.handler.PresenterHandler;

public class MultiPresentersEventFilter implements
		EventFilter<MultiPresentersEventBus> {

	/** Have access to the presenterHandler instance */
	@Inject
	private PresenterHandler presenterHandler;

	/** Get the list of grouped events from the generated GroupEventList class */
	private List<String> groupedEvents = GWT.create(GroupEventList.class);

	public boolean filterEvent(String eventName, Object[] params,
			MultiPresentersEventBus eventBus) {
		// Deactivate presenters registered for a group in the list
		if (groupedEvents.contains(eventName)) {
			presenterHandler.activateGroup((String) params[0]);
		}
		// Always return true to forward event to all "active" handlers
		return true;
	}

}
